﻿<?php
include ("../conn.php");
if(isset($_POST['submit']))
{
echo $title=$_POST['title'];
$content=$_POST['content'];
$sql="INSERT INTO `news`(`title` ,`content` ,`time`) VALUES ('".$title."','".$content."',now())";
mysqli_query($con,$sql);
echo "　　添加成功！";
}
?>
<div>
	<script>
		function Checkadd()
		{
			if(myform.title.value=="")
			{
			  alert("标题不能为空");
			  myform.title.focus();
			  return false;
		  }
		  if(myform.content.value=="")
		  {
		  	alert("新闻内容不能为空");
		  	myform.content.focus();
		  	return false;
		  }
		}
	</script>
	<form style="margin:0;padding:0;" name=myform method=post action="?" onsubmit="return Checkadd();">
		新闻标题：<input name=title type=text /><br />
		新闻内容：<br /><textarea name=content cols=50 rows=15></textarea><br />
		<input type=submit name=submit value=添加 />
	</form>
</div>